﻿
; (function () {
    var page = {
        relativeUrl: '',
        finishList: [],
        unFinishList: [],
        printTotal: 0,
        dateIndex: 0,
        editSchedule: true,
        scheduleBreakFlag: false, //爽约标志
        scheduleExamRequestOld: {},
        today:'',
        //页面初始化
        init: function () {
            if($('#hdnEmptyPage').val() == "1"){
                return;
            }

            page.finishList.current = 0;
            page.unFinishList.current = 0;
            page.relativeUrl =  $('#hdnRelativeUrl').val();
            page.schedule = new Schedule("Self", page.relativeUrl);
            pageEvent.init();
            page.schedule.days = 7;

            setTimeout(function () {
                if (printAssistType == "1") {
                    IMCISAssistTool.printPlatform = "ImicsSelf";
                    IMCISAssistTool.testAssistToolUsePort();
                } else {
                    var lodop = getLodop().lodop;
                    if ($.trim(SelfPrintReceipt) != '0' && !lodop) {
                        page.schedule.alert("请先安装打印插件（自助机程序Dependencies目录下CLodop_Setup_for_Win32NT.exe）");
                        $('.layui-layer-content').css({ 'height': '112px' });
                    }
                }
            }, 2000);

            page.schedule.queryCondition.ScheduleRoute = scheduleRoute;
            page.schedule.getExamRequestList(page.getExamRequestListCallback, function(errorMsg){
                $('#main_container .b_no_data').html(errorMsg);
                page.setWindowCenter()
            });
        },
        
        //获取申请单列表+1
        getExamRequestListCallback: function (data) {
            page.schedule.examRequestList = data;
            $('.b_name').text(data[0].Name);
            $('.b_department').text(data[0].RequestDeptName || "");

            var list = [];
            for (var i = 0; i < data.length; i++) {
                var j = 0;
                if(data[i].NeedScheduleFlag){
                    list.splice(j,0,data[i]);
                    j++;
                } else {
                    list.push(data[i]);
                }
            }

            if (list.length > 0)
                var param = {
                    OutPatientNO: list[0].OutPatientNO,
                    InPatientNO: list[0].InPatientNO,
                    CardNO: list[0].CardNO,
                    IDCardNO: list[0].IDCardNO,
                    PatientMasterID: list[0].PatientMasterID,
                    MedRecNO: list[0].MedRecNO,
                    ScheduleRoute: scheduleRoute
                };
                page.schedule.CheckPatientLimit(param, function (ret) {
                    scheduleLimit = ret.scheduleLimit;
                    limitMsg = ret.limitMsg;
                    if (scheduleLimit == "1")
                        pageEvent.scheduleLimit();
                });

            for (var i = 0; i < list.length; i++) {
                list[i].ScheduleRoute = (scheduleRoute || 4);
                if(list[i].orderList && list[i].orderList.length > 0){
                    $.each(list[i].orderList, function(j, m){
                        list[i].orderList[j].ScheduleRoute = scheduleRoute || 4;
                    });
                }
                //该申请单自助预约已预约列表显示检查状态。
                var selfScheduleListResultStatusOfExamRequest = page.schedule.GetSysParameterValueByExamRequest(list[i], scheduleSelfScheduleListResultStatus);

                //待预约数据状态为已签到的在已签到显示
                var signInStatus = page.schedule.GetSysParameterValueByExamRequest(list[i], signInCompletedByResultStatus);

                //如显示未预约列表
                if (scheduleSelfShowUnScheduleList) {
                    if ((!selfScheduleListResultStatusOfExamRequest && list[i].ScheduleFlag && (list[i].ResultStatus == "预约完成" || list[i].ResultStatus == "登记完成")) ||
                   (selfScheduleListResultStatusOfExamRequest && list[i].ScheduleFlag && selfScheduleListResultStatusOfExamRequest.indexOf(list[i].ResultStatus) > -1)) {
                        var allowPrint = true;
                        //允许打印并还没有打印过的申请单默认勾选
                        if (scheduleSelfPrintExamScheduleReceiptPayment && !list[i].PaymentsFlag) {
                            var allowNotPaymentPrint = page.schedule.GetSysParameterValueByExamRequest(list[i], scheduleSelfPrintExamScheduleReceiptPayment);
                            if (allowNotPaymentPrint === "0") {
                                allowPrint = false;
                            }
                        }
                        var allowPrintCount = page.schedule.GetSysParameterValueByExamRequest(list[i], scheduleSelfPrintExamScheduleReceiptTimes);
                        if (!allowPrintCount && list[i].ReceiptPrintCount != null && list[i].ReceiptPrintCount >= 1) {
                            allowPrint = false;
                        } else if (list[i].ReceiptPrintCount != null && allowPrintCount !== '' && list[i].ReceiptPrintCount >= allowPrintCount) {
                            allowPrint = false;
                        }
                        if (allowPrint && (list[i].ReceiptPrintCount == null || list[i].ReceiptPrintCount == 0)) {
                            list[i].printFlag = true;
                            page.printTotal++;
                        }
                        page.finishList.push(list[i]);
                        //是否大于两条
                        if (page.finishList.length < 3) {
                            page.bindFinish(list[i], page.finishList.length);
                        }
                    }
                    else if (!list[i].ScheduleFlag) {
                        if (signInStatus.indexOf(list[i].ResultStatus) > -1) {
                            continue;
                        }
                        page.unFinishList.push(list[i]);
                        //是否大于两条
                        if (page.unFinishList.length < 3) {
                            page.bindUnFinish(list[i], page.unFinishList.length);
                        }
                    } else {
                        //签到完成,自助预约没有签到完成
                    }
                } else {//不显示未预约列表

                    if ((!selfScheduleListResultStatusOfExamRequest && list[i].ScheduleFlag && (list[i].ResultStatus == "预约完成" || list[i].ResultStatus == "登记完成")) ||
                   (selfScheduleListResultStatusOfExamRequest && list[i].ScheduleFlag && selfScheduleListResultStatusOfExamRequest.indexOf(list[i].ResultStatus) > -1)) {
                        var allowPrint = true;
                        //允许打印并还没有打印过的申请单默认勾选
                        if (scheduleSelfPrintExamScheduleReceiptPayment && !list[i].PaymentsFlag) {
                            var allowNotPaymentPrint = page.schedule.GetSysParameterValueByExamRequest(list[i], scheduleSelfPrintExamScheduleReceiptPayment);
                            if (allowNotPaymentPrint === "0") {
                                allowPrint = false;
                            }
                        }
                        var allowPrintCount = page.schedule.GetSysParameterValueByExamRequest(list[i], scheduleSelfPrintExamScheduleReceiptTimes);
                        if (!allowPrintCount && list[i].ReceiptPrintCount != null && list[i].ReceiptPrintCount >= 1) {
                            allowPrint = false;
                        } else if (list[i].ReceiptPrintCount != null && allowPrintCount !== '' && list[i].ReceiptPrintCount >= allowPrintCount) {
                            allowPrint = false;
                        }
                        if (allowPrint && (list[i].ReceiptPrintCount == null || list[i].ReceiptPrintCount == 0)) {
                            list[i].printFlag = true;
                            page.printTotal++;
                        }
                        page.finishList.push(list[i]);
                        //是否大于五条
                        if (page.finishList.length < 5) {
                            page.bindFinish(list[i], page.finishList.length);
                        }
                    }
                }
            }

            if (scheduleSelfShowUnScheduleList) {
                if (page.finishList.length > 2) {
                    $('.finishright img').css('visibility', 'visible');
                }
                $('.booknum').text('（' + page.finishList.length + '）');

                if (page.unFinishList.length > 2) {
                    $('.unfinishright img').css('visibility', 'visible');
                }
                $('.unbooknum').text('（' + page.unFinishList.length + '）');

                page.showMultiBtn();

                $('#print').text('打印预约单' + (page.printTotal === 0 ? "" : "（" + page.printTotal + "）"));
            } else {
                $('.ifbook_container')[0].style.display = 'none';
                if (page.finishList.length > 4) {
                    $('.finishright img').css('visibility', 'visible');
                }
                $('.booknum').text('（' + page.finishList.length + '）');

                $('#print').text('打印预约单' + (page.printTotal === 0 ? "" : "（" + page.printTotal + "）"));
            }

            $('.un-finish-container .not_schedule').on('click', function (e) {
                if (pageEvent.scheduleLimit()) {
                    return false;
                }
                pageEvent.showNotScheduleMemo($(this), page.unFinishList);
                if (e && e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    window.event.cancelBubble = true;
                }

            });
            $('.finish-container .not_schedule').on('click', function (e) {
                pageEvent.showNotScheduleMemo($(this), page.finishList);
            });
            
            if(selfAutoScheduleFlag && page.unFinishList.length > 0) {
                setTimeout(pageEvent.saveMultiExamSchedule, 500);
            }
            page.setWindowCenter()
        },

        //未预约+1
        bindUnFinish: function (exam, i) {
            if(!exam){
                return;
            }
            var temp = '<div class="ifbook_items pull-left" data-placerorderno=' + exam.PlacerOrderNO + '>' +
                            '<div class="row check_detail">' +
                                '<table>' +
                                    '<tr>' +
                                        '<td>' + i + '.<span class="apply_procedure-name">' + exam.ServiceSectID + "  " + exam.ProcedureName + '<span></td>' +
                                    '</tr>' +
                                    '<tr>' +
                                        '<td class="apply_time">申请时间：' + imcis.convertDateFromJson(exam.RequestedDate) + '</td>' +
                                    '</tr>' +
                                    '<tr>' +
                                        '<td class="apply_room">申请科室：'+exam.RequestDeptName+'</td>' +
                                    '</tr>' +
                                '</table>' +
                            '</div>';

            if (exam.NeedScheduleFlag && scheduleLimit != "3") {
                temp += '<div class="start_boook unbook_itemslist" data-self="1">选择预约时间</div>';
            } else {
                temp += '<div class="start_boook unbook_itemslist not_schedule" data-self="0">' + '不提供自助预约' + '</div>';
            }
            temp +=  '</div>';
            $('#main_container .un-finish-container').append(temp);
        },

        //已预约+1
        bindFinish: function (exam, i) {
            if(!exam){
                return;
            }
            var startDate = imcis.convertDateFromJson(exam.ScheduleStartDate);
            var endDate = imcis.convertDateFromJson(exam.ScheduleEndDate);
            var scheduleTime = startDate.substr(0, 16) + "-" + endDate.substr(11, 5);
            var ScheduleNotice = exam.ScheduleNotice;
            var ScheduleNoticehtml = '';
            if (ScheduleNotice) {
                ScheduleNoticehtml = '<div class="attation">注意事项</div>'
            }

            var temp = '<div class="ifbook_items pull-left" style="position:relative" data-placerorderno=' + exam.PlacerOrderNO + ' data-scheduletime="' + scheduleTime + '" data-servicesectid="' + exam.ServiceSectID + '">' +
                    ' <div class="print_img ' + (exam.printFlag ? 'print_img_check' : 'print_img_cancel ')+'"></div>' +
                       ScheduleNoticehtml+
                        '<div class="row check_detail">' +
                            '<table>' +
                                '<tr>' +
                                    '<td>' + i + '.<span class="apply_procedure-name">' + exam.ServiceSectID + "  " + exam.ProcedureName + '<span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="apply_time">预约时间：' + scheduleTime  + '</td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="apply_add">检查地点：' + (exam.ResourceLocation||'') + '</td>' +
                                '</tr>' +
                            '</table>' +
                        '</div>' +
                        '<div class="change_items">';

            if (exam.NeedScheduleFlag) {
                var scheduleRouteStr = imcis.schedule.getScheduleRouteStr(scheduleRoute);
                exam.allowUpdateSchedule = page.schedule.ScheduleAutoNotAllowCancelOrEditByScheduleDateAhead(exam, ScheduleAutoNotAllowEditByScheduleDateAhead);//判断是否允许修改预约
                if(exam.ResultStatus && exam.allowUpdateSchedule && editResultStatus) {
                    var resultStatus = imcis.schedule.getSysParamValueByScheduleRoute(editResultStatus, scheduleRouteStr, exam.ServiceSectID, exam.PatientClass);

                    if(resultStatus && resultStatus.indexOf(exam.ResultStatus) == -1) {
                        exam.allowUpdateSchedule = false;
                        exam.editResultStatus = false;
                        exam.ScheduleRouteStr = scheduleRouteStr;
                    }
                }
                exam.allowCancelSchedule = page.schedule.ScheduleAutoNotAllowCancelOrEditByScheduleDateAhead(exam, ScheduleAutoNotAllowCancelByScheduleDateAhead)//判断是否允许取消预约
                if(exam.ResultStatus && exam.allowCancelSchedule && cancelResultStatus) {
                    var resultStatus = imcis.schedule.getSysParamValueByScheduleRoute(cancelResultStatus, scheduleRouteStr, exam.ServiceSectID, exam.PatientClass);
                    if ($.trim(resultStatus) == "" || (resultStatus && resultStatus.indexOf(exam.ResultStatus) == -1)) {
                        exam.allowCancelSchedule = false;
                        exam.CancelResultStatusFlag = true;
                        exam.ScheduleRouteStr = scheduleRouteStr;
                    }
                }

                var allowSelfEditTimes = page.schedule.GetSysParameterValueByExamRequest(exam, scheduleAllowSelfEditTimes);
                var allowSelfEditFlag = true;
                var selfEditTimes = exam.SelfEditTimes == null ? 0 : exam.SelfEditTimes;
                if ($.trim(allowSelfEditTimes) != "") {
                    allowSelfEditFlag = selfEditTimes < parseInt(allowSelfEditTimes);
                }

                var allowSelfCancelTimes = page.schedule.GetSysParameterValueByExamRequest(exam, scheduleAllowSelfCancelTimes);
                var allowSelfCancelFlag = true;
                var selfCancelTimes = exam.SelfCancelTimes == null ? 0 : exam.SelfCancelTimes;
                if ($.trim(allowSelfCancelTimes) != "") {
                    allowSelfCancelFlag = selfCancelTimes < parseInt(allowSelfCancelTimes);
                }

                var allowEditTime = page.schedule.GetSysParameterValueByExamRequest(exam, ScheduleAutoNotAllowEditByScheduleDateAhead);
                var allowCancelTime = page.schedule.GetSysParameterValueByExamRequest(exam, ScheduleAutoNotAllowCancelByScheduleDateAhead);
                var scheduleStartDate = exam.ScheduleStartDate;

                if (exam.allowUpdateSchedule == true && scheduleLimit != "3" && allowSelfEditFlag)//scheduleLimit 爽约限制 = 3
                {
                    temp += '<div class="pull-left edit_book" data-allowTimes="' + allowSelfEditTimes + '" data-editTimes="' + selfEditTimes +'">修改预约</div>';
                } else {
                    var notEditType = "", status = "";
                    if (exam.allowUpdateSchedule != true) {
                        notEditType = "allowUpdateSchedule";
                        status = exam.editResultStatus == false ? exam.ResultStatus : "";   //不允许修改
                    } else if (!allowSelfEditFlag) {
                        notEditType = "allowSelfEditTimes";
                    } else if (scheduleLimit == "3") {
                        notEditType = "scheduleLimit";
                    }
                    temp += '<div class="pull-left unedit_book" data-notEditType="' + notEditType + '" data-editTimes="' + selfEditTimes + '" data-allowUpdateTimes="' + allowEditTime + '" data-ScheduleStartDate="' + scheduleStartDate + '" data-resultStatus="' + status + '" data-patientClass="' + exam.PatientClass + '" data-serviceSectID="' + exam.ServiceSectID + '" data-scheduleRoute="' + exam.ScheduleRouteStr + '">不提供修改</div>';
                }
                if (exam.allowCancelSchedule == true && scheduleLimit != "3" && allowSelfCancelFlag) {
                    temp += '<div class="pull-left cancel_book" data-allowTimes="' + allowSelfCancelTimes + '" data-cancelTimes="' + selfCancelTimes +'">取消预约</div>';
                } else {
                    var notCancelType = "";
                    if (exam.allowCancelSchedule != true && exam.CancelResultStatusFlag == true) {
                        notCancelType = "cancelResultStatus";
                    } else if (exam.allowCancelSchedule != true) {
                        notCancelType = "allowCancelSchedule";
                    } else if (!allowSelfCancelFlag) {
                        notCancelType = "allowSelfCancelTimes";
                    } else if (scheduleLimit == "3") {
                        notCancelType = "scheduleLimit";
                    }

                    temp += '<div class="pull-left uncancel_book" data-notCancelType="' + notCancelType + '" data-cancelTimes="' + selfCancelTimes + '" data-allowCancelTimes="' + allowCancelTime + '" data-ScheduleStartDate="' + scheduleStartDate + '" data-resultStatus="' + exam.ResultStatus + '" data-patientClass="' + exam.PatientClass + '" data-serviceSectID="' + exam.ServiceSectID + '" data-scheduleRoute="' + exam.ScheduleRouteStr + '">不提供取消</div>';
                }
            } else {               
                temp += '<div class="start_boook unbook_itemslist not_schedule" data-self="0">' + (exam.OperationMemo ? exam.OperationMemo.length > 10 ? exam.OperationMemo.substr(0, 8) + '...' : exam.OperationMemo : '不提供自助预约') + '</div>';
            }

            temp +='</div></div>';

            $('#main_container .finish-container').append(temp);
        },
        // 设置屏幕居中
        setWindowCenter: function () {
            var mainHeight = $('#sel_container').height() + $('.self-tips-msg').height() + 70;
            if ($(window).height() > mainHeight) {
                $('#sel_container').css('margin-top', ($(window).height() - mainHeight)/2)
            }
        },
        showMultiBtn:function(){
            var canAuto = false;
            for (var i = 0; i < page.unFinishList.length; i++) {
                if(page.unFinishList[i].NeedScheduleFlag){
                    canAuto = true;
                    break;
                }
            }

            if (canAuto && scheduleSelfShowSaveMultiButton) {
                $('#saveMulti').show();
            } else{
                $('#saveMulti').hide();
            }
        }
    };

    var pageEvent = {
        //事件初始化
        init: function () {
            //取消预约+1
            $('#main_container').on('click', '.cancel_book', pageEvent.cancelSchedule);
            //修改预约时间
            $('#main_container').on('click', '.edit_book', pageEvent.editSchedule);
            //未预约开始预约
            $('#main_container').on('click', '.unbook_itemslist', pageEvent.startSchedule);
            //不提供修改预约时间
            $('#main_container').on('click', '.unedit_book', pageEvent.scheduleLimit);
            //不提供取消预约时间
            $('#main_container').on('click', '.uncancel_book', pageEvent.scheduleLimit);
            
            //一键预约多个检查申请+1
            $('#saveMulti').on('click', function () {
                if (page.unFinishList.length == 0) {
                    page.schedule.alert('目前您没有未预约的检查申请!');
                } else {
                    page.schedule.comfirm('是否一键预约保存!', function () {
                        pageEvent.saveMultiExamSchedule();
                    });  
                }
            });

            //保存预约+1
            $('#save_time').on('click',   pageEvent.saveExamSchedule);

            //切换日期
            $('#time_container').on('click', '.day_items', function () {
                if ($(this).text().trim() == "其他时间") {
                    //月列表展示
                    /**时间**/
                    var myd = $('.second_list .actived_item .myd').text().trim().split('-');
                    var year = myd[0];
                    var month = myd[1];
                    var today = myd[2];
                    $('#year').text(year);
                    $('#month').text(month);
                    page.today = today;
                    pageEvent.choseMonthArr(year, month);
                    $('.time_container').hide();
                    $('#timeContainer').show();
                } else {
                    $('.time_container').show();
                    $('#timeContainer').hide();
                    pageEvent.changeDate(this);
                }
            });
           
            //切换时间组
            $('.ampm_container').on('click', '.ampm', pageEvent.changeGroup);
            //选中时间
            $('#time_container').on('click', '.schedule-time', pageEvent.selectTime);

            //时间页面返回+1
            $('#time_container').on('click', '#backTo', function () {
                $('#time_container').hide();
                $('#main_container').show();
            });

            //选中打印的条数
            $('.finish-container').on('click', '.check_name, .check_detail,.print_img ', pageEvent.selectPrint);
            //打印
            $('#print').on('click', pageEvent.print);
            //左右移动
            $('#main_container').on('click', '.arrow_position', pageEvent.moveSchedule);
            
            //月份切换
            $('#Timeback').click(function () {
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var newMonth = Number($('#month').text()) - 1;
                page.today = "";
                var newyear = Number($('#year').text());
                var newmoth = Number($('#month').text());
                if (year == newyear && newmoth > month) {
                    if (newMonth == 0) {
                        newMonth = 12
                        $('#year').text(Number($('#year').text()) - 1);
                    }
                    $('#month').text(newMonth);
                    pageEvent.choseMonthArr(newyear, newmoth-1);
                } else if (year < newyear) {
                    if (newMonth == 0) {
                        newMonth = 12
                        $('#year').text(Number($('#year').text()) - 1);
                    }
                    $('#month').text(newMonth);
                    pageEvent.choseMonthArr(newyear, newmoth-1);
                }
               
            });

            $('#Timenext').click(function () {
                var newMonth = Number($('#month').text()) + 1;
                if (newMonth > 12) {
                    newMonth = 1
                    $('#year').text(Number($('#year').text()) + 1);
                }
                $('#month').text(newMonth);
                page.today = "";
                pageEvent.choseMonthArr(Number($('#year').text()), Number($('#month').text()));
            });

            //选中时间
            $('#timeContainer').on('click', '.days_list .days', function () {
                var daysArr = $('#timeContainer .days_list .days');
                if (!$(this).data('cantchose')) {
                    $.each(daysArr, function (i, n) {
                        daysArr.eq(i).removeClass('font_blue');
                    });
                   $(this).addClass('font_blue'); }
                
            });
            //日历确定
            $('#timeContainerSure').click(function () {
                $("#timeContainer").hide();
                $('.time_container').show();
                page.schedule.startDate = $('#year').text() + '-' + $('#month').text() + '-' + $('#timeContainer .font_blue').text();
                page.schedule.IgnoreScheduleFlag = true;
                page.schedule.getScheduleInfo(page.scheduleExamRequest, [], "", "", null, pageEvent.getScheduleInfoCallback);
            });

            $('#main_container').on('click', '.attation', pageEvent.showScheduleNotice);

            $('#back').on('click', pageEvent.back);
        },
        //时间列表
        choseMonthArr: function (year, month) {
            var date = new Date();
            var now_year = date.getFullYear();
            var now_month = date.getMonth() + 1;
            var now_day = date.getDate();
            days = pageEvent.monthLong(year, month) + 1;//一个月几天
            var html = '';
            //每个月的第一天是周几
            var addMonth = '';
            if (month >= 10) {
                addMonth = month;
            } else {
                addMonth = '0' + month;
            }
            // firtdatweeknum 0-6 对应 "星期日"-"星期六"
            var firtdatweeknum = new Date(year + '/' + addMonth + '/01').getDay();
            if (firtdatweeknum != 7) {
                firtdatweeknum = firtdatweeknum == 0 ? 7 : firtdatweeknum;
                for (var i = 0; i < firtdatweeknum - 1; i++) {
                    html += '<div><div class="days"></div></div>';
                }
            }
            for (var i = 1; i < days; i++) {
                if (now_year == year && now_month == month && i < now_day) {
                    html += '<div><div class="days font_gray" data-cantchose="1">' + i + '</div></div>';
                } else {
                    if (i == page.today) {
                        html += '<div><div class="days font_blue">' + i + '</div></div>';
                    } else {
                        html += '<div><div class="days">' + i + '</div></div>';
                    }
                }
               
            }
            $('.days_list').html('')
            $('.days_list').append(html)
        },
        //一个月有几天
        monthLong:function(year, month) {
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                return 31;
            }
            if (month == 2) {
                if (year % 4 == 0) {
                    return 29;
                } else {
                    return 28;
                }
            }
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                return 30;
            }
        },

        //取消预约+1
        cancelSchedule: function () {
            var $this = $(this);
            var exam = null, index = 0;
            var placerOrderNO = $this.closest('.ifbook_items').data("placerorderno");
            $.each(page.finishList, function (i, n) {
                if (n.PlacerOrderNO == placerOrderNO) {
                    exam = n;
                    index = i;
                    return false;
                }
            });
            var cancelSchedule = function (scheduleBreakFlag, tips) {
                page.schedule.comfirm(tips, function () {
                    page.schedule.cancelSchedule({
                        'PlacerOrderNO': placerOrderNO,
                        'ScheduleRoute': (scheduleRoute || 4),
                        'ScheduleBreakFlag': scheduleBreakFlag,
                        'OrganizationID': exam.OrganizationID
                    }, function (data) {
                        if (data && !data.success && data.writebackFailItem) {
                            page.schedule.alert("取消预约回写失败，请到服务台处理。");
                        }

                        if (exam.printFlag) {
                            exam.printFlag = false;
                            page.printTotal--;
                            $('#print').text('打印预约单' + (page.printTotal <= 0 ? "" : "（" + page.printTotal + "）"));
                        }

                        exam.ResultStatus = "取消预约";
                        exam.ScheduleStatus = 1;
                        exam.SelfCancelTimes = exam.SelfCancelTimes == null ? 1 : exam.SelfCancelTimes++;
                        //exam.SelfCancelTimes += 1;

                        if (page.unFinishList.length > 0) {
                            for (var i = 0; i < page.unFinishList.length; i++) {
                                if (!page.unFinishList[i].NeedScheduleFlag) {
                                    page.unFinishList.splice(index, 0, exam);
                                    break;
                                }
                            }
                        } else {
                            page.unFinishList.push(exam);
                        }
                        page.finishList.splice(index, 1);
                        page.showMultiBtn();

                        $('.booknum').text('（' + page.finishList.length + '）');
                        $('.unbooknum').text('（' + page.unFinishList.length + '）');

                        $('#main_container .un-finish-container').html('');
                        for (var i = 0; i < page.unFinishList.length; i++) {
                            if (i < 2) {
                                page.bindUnFinish(page.unFinishList[i], i + 1);
                            }
                        }

                        if (page.unFinishList.length > (page.unFinishList.current + 1) * 2) {
                            $('.unfinishright img').css('visibility', 'visible');
                        }

                        $('#main_container .finish-container').html('');
                        if (page.finishList.length >= (page.finishList.current + 1) * 2) {
                            page.bindFinish(page.finishList[page.finishList.current * 2], page.finishList.current * 2 + 1);
                            page.bindFinish(page.finishList[page.finishList.current * 2 + 1], page.finishList.current * 2 + 2);
                        } else if (page.finishList.length > page.finishList.current * 2 && page.finishList.length < (page.finishList.current + 1) * 2) {
                            page.bindFinish(page.finishList[page.finishList.current * 2], page.finishList.current * 2 + 1);
                        } else {
                            if (page.finishList.current > 0) {
                                page.finishList.current--;
                                page.bindFinish(page.finishList[page.finishList.current * 2], page.finishList.current * 2 + 1);
                                page.bindFinish(page.finishList[page.finishList.current * 2 + 1], page.finishList.current * 2 + 2);
                            }
                        }
                        if (page.finishList.length <= 2) {
                            $('.finishright').find('img').css('visibility', 'hidden');
                            $('.finishleft').find('img').css('visibility', 'hidden');
                        }
                    });
                });
            };

            var tipStr = "是否取消预约？";
            var allowTimes = $this.attr("data-allowTimes");
            if ($.trim(allowTimes) != "") {
                var surplusTimes = parseInt(allowTimes) - (exam.SelfCancelTimes == null ? 0 : exam.SelfCancelTimes);
                if (surplusTimes > 0) {
                    tipStr = "自助取消预约剩余" + surplusTimes + "次，请谨慎取消。<br>确定取消预约？";
                } else {
                    page.schedule.alert("自助取消预约已超过" + allowTimes + "次，如有需要请联系相关科室。");
                    $this.removeClass("edit_book").addClass("unedit_book").html("不提供取消");
                    return false;
                }
            }

            //爽约
            var requestExam = exam;
            requestExam.ScheduleStartTimeDetail = imcis.convertDateFromJson(requestExam.ScheduleStartTimeDetail);
            requestExam.ScheduleEndTimeDetail = imcis.convertDateFromJson(requestExam.ScheduleEndTimeDetail);
            var cancelScheduleDate = page.schedule.GetSysParameterValueByExamRequest2(requestExam, scheduleBreakCancelByScheduleDateAhead);
            if (cancelScheduleDate != "") {
                if (new Date() >= new Date(page.schedule.GetDateByExamAndParam(requestExam, cancelScheduleDate) + ":00")) {
                    var tips = page.schedule.GetSysParameterValueByExamRequest2(requestExam, scheduleBreakCancelTip);
                    cancelSchedule(true, (tips == "" ? "" : "取消预约会被记录为爽约！<br/>原因：" + tips));
                } else {
                    cancelSchedule(false, tipStr);
                }
            } else {
                cancelSchedule(false, tipStr);
            }
        },

        //修改预约时
        editSchedule: function () {
            var $this = $(this);
            page.editSchedule = true;
            var placerOrderNO = $(this).closest('.ifbook_items').data('placerorderno');
            $.each(page.finishList, function (i, n) {
                if (n.PlacerOrderNO == placerOrderNO) {
                    //n.printFlag = !n.printFlag;
                    page.scheduleExamRequest = n;
                    return false;
                }
            });
            var allowTimes = $this.attr("data-allowTimes");
            if ($.trim(allowTimes) != "") {
                var surplusTimes = parseInt(allowTimes) - (page.scheduleExamRequest.SelfEditTimes == null ? 0 : page.scheduleExamRequest.SelfEditTimes);
                if (surplusTimes > 0) {
                    page.schedule.alert("自助预约剩余"+ surplusTimes + "次，请谨慎修改。");
                } else {
                    page.schedule.alert("自助预约已超过" + allowTimes + "次，如有需要请联系相关科室。");
                    $this.addClass("unedit_book").html("不提供修改");
                    return false;
                }
            }
            $('.day_items span').text('');
            $('.ampm_title').html('');
            $('#time_detail_container').html('');
            $('#main_container').hide();
            $('#time_container').show();

            $('.ServiceSectID').text(page.scheduleExamRequest.ServiceSectID);
            $('.ProcedureName').text(page.scheduleExamRequest.ProcedureName);

            page.scheduleExamRequestOld = JSON.parse(JSON.stringify(page.scheduleExamRequest));
            page.schedule.IgnoreScheduleFlag = false;
            page.schedule.getScheduleInfo(page.scheduleExamRequest, [], "", "", null, pageEvent.getScheduleInfoCallback);
        },

        //开始预约
        startSchedule: function () {
            var $this = $(this);
            if($this.data('self') == "0"){
                return;
            }
            if ($("#sel_container").width() < 1000) {
                $(".time_list").css("margin", "-1px 3px 0 3px");
                $(".ampm_container").css("padding", "20px 3px 0 3px");
                $(".second_list").css("padding", "20px 0 0 3px");
            }
            $('.day_items span').text('');
            $('.ampm_title').html('');
            $('#time_detail_container').html('');

            $('#main_container').hide();
            $('#time_container').show();
            page.editSchedule = false;
            var placerOrderNO = $(this).closest('.ifbook_items').data('placerorderno');
            $.each(page.unFinishList, function (i, n) {
                if (n.PlacerOrderNO == placerOrderNO) {
                    //n.printFlag = !n.printFlag;
                    page.scheduleExamRequest = n;
                    return false;
                }
            });

            $('.ServiceSectID').text(page.scheduleExamRequest.ServiceSectID);
            $('.ProcedureName').text(page.scheduleExamRequest.ProcedureName);
            page.schedule.IgnoreScheduleFlag = true;
            page.schedule.getScheduleInfo(page.scheduleExamRequest, [], "", "", null, pageEvent.getScheduleInfoCallback);
        },

        //保存单个预约
        saveExamSchedule: function () {
            var $this = $(this);
            var promptDetail = $this.data('promptdetail') || '';
            if(promptDetail == "1" || (promptDetail == "2" && page.scheduleExamRequest.ScheduleStatus === 0)) {
                promptDetail = "预约时间" + page.scheduleExamRequest.ScheduleStartDate + '-' + page.scheduleExamRequest.ScheduleEndDate.substring(11) + "。确认预约？";
            } else {
                promptDetail = "";
            }

            //修改时爽约提示    
            if (page.editSchedule) {
                page.scheduleBreakFlag = false; //恢复成false
                page.scheduleExamRequestOld.ScheduleStartTimeDetail = imcis.convertDateFromJson(page.scheduleExamRequestOld.ScheduleStartTimeDetail);
                page.scheduleExamRequestOld.ScheduleEndTimeDetail = imcis.convertDateFromJson(page.scheduleExamRequestOld.ScheduleEndTimeDetail);
                var editScheduleDate = page.schedule.GetSysParameterValueByExamRequest2(page.scheduleExamRequestOld, scheduleBreakEditByScheduleDateAhead);
                if (editScheduleDate != "") {
                    if (new Date() >= new Date(page.schedule.GetDateByExamAndParam(page.scheduleExamRequestOld, editScheduleDate) + ":00")) {
                        page.scheduleBreakFlag = true;
                        var tips = page.schedule.GetSysParameterValueByExamRequest2(page.scheduleExamRequestOld, scheduleBreakEditTip);
                        if (tips != "") {
                            promptDetail = "修改预约会被记录为爽约！<br/>原因：" + tips;
                        }
                    }
                } 
            }

            if(promptDetail){
                page.schedule.comfirm(promptDetail, function () {
                    pageEvent.saveExamScheduleExecute($this);
                });
            } else {
                pageEvent.saveExamScheduleExecute($this);
            }
        },

        saveExamScheduleExecute: function($this){
            page.schedule.saveExamSchedule(page.scheduleExamRequest, page.scheduleBreakFlag, function (data) {
                var placerOrderNO = page.scheduleExamRequest.PlacerOrderNO;
                if (data && data.length > 0) {
                    $.each(data, function (i, n) {
                        if (placerOrderNO == n.PlacerOrderNO) {
                            page.scheduleExamRequest.ScheduleResourceUID = n.ScheduleResourceUID;
                            page.scheduleExamRequest.ScheduleResourceName = n.ScheduleResourceName;
                            page.scheduleExamRequest.ScheduleStartDate = n.ScheduleStartDate;
                            page.scheduleExamRequest.ScheduleEndDate = n.ScheduleEndDate;
                            page.scheduleExamRequest.ResourceLocation = n.ResourceLocation;
                            page.scheduleExamRequest.ScheduleNotice = n.ScheduleNotice;
                            page.scheduleExamRequest.ObservationUID = n.ObservationUID;
                            page.scheduleExamRequest.ScheduleFlag = true;
                            page.scheduleExamRequest.ScheduleStatus = 0;
                            page.scheduleExamRequest.SelfEditTimes = page.scheduleExamRequest.SelfEditTimes == null ? 1 : page.scheduleExamRequest.SelfEditTimes++;

                            return false;
                        }
                    });

                    try {
                        var result = SelfClientBound.save(placerOrderNO);

                        if (result) {
                            page.schedule.alert(result);
                        }
                    } catch (ex) { }
                } 

                //检查申请的保存
                if (!page.editSchedule) {
                    $('.ifbook_items[data-PlacerOrderNO="' + placerOrderNO + '"]').remove();

                    $.each(page.unFinishList, function (i, n) {
                        if (n.PlacerOrderNO == placerOrderNO) {
                            page.scheduleExamRequest.printFlag = true;
                            page.scheduleExamRequest.ResultStatus = "预约完成";
                            page.printTotal++;
                            page.bindFinish(page.scheduleExamRequest, page.finishList.length);
                            page.finishList.push(page.scheduleExamRequest);
                            page.unFinishList.splice(i, 1);
                            pageEvent.bindAfterSave();
                            return false;
                        }
                    });
                } else {
                    //已预约的修改
                    $.each(page.finishList, function (i, n) {
                        if (n.PlacerOrderNO == placerOrderNO) {
                            n.ScheduleResourceUID = page.scheduleExamRequest.ScheduleResourceUID;
                            n.ScheduleResourceName = page.scheduleExamRequest.ScheduleResourceName
                            n.ScheduleStartDate =  page.scheduleExamRequest.ScheduleStartDate;
                            n.ScheduleEndDate = page.scheduleExamRequest.ScheduleEndDate;
                            n.ResourceLocation = page.scheduleExamRequest.ResourceLocation;
                            n.ScheduleNotice = page.scheduleExamRequest.ScheduleNotice;
                            n.ObservationUID = page.scheduleExamRequest.ObservationUID;
                            if(!page.scheduleExamRequest.printFlag){
                                page.scheduleExamRequest.printFlag = true;
                                n.printFlag = true;
                                page.printTotal++;
                            }                            
                            var $item = $('.ifbook_items[data-PlacerOrderNO="' + placerOrderNO + '"]');
                            $(this).parent().find('.print_img').removeClass('print_img_cancel').addClass('print_img_check');
                            $item.find('.apply_time').text(page.scheduleExamRequest.ScheduleDate + " " + page.scheduleExamRequest.StartTime + "-" + page.scheduleExamRequest.EndTime);
                            $item.find('.apply_add').text('检查地点：' + (page.scheduleExamRequest.ResourceLocation|| ""));
                            $('#print').text('打印预约单' + (page.printTotal === 0 ? "" : "（" + page.printTotal + "）"));
                            return false;
                        }
                    });
                }

                if(page.unFinishList.length == 0){
                    try{
                        var result = SelfClientBound.finish();

                        if(result) {
                            page.schedule.alert(result);
                        }
                    }catch(ex){}
                }

                page.showMultiBtn();
                $('#main_container').show();
                $('#time_container').hide();
                page.scheduleExamRequest = Schedule.transExamRequestDatetime(page.scheduleExamRequest);
                $('.ifbook_items[data-placerorderno="' + placerOrderNO + '"]').find('.apply_time').text(page.scheduleExamRequest.ScheduleStartDate + '-' + page.scheduleExamRequest.ScheduleEndDate.substring(page.scheduleExamRequest.ScheduleEndDate.length, page.scheduleExamRequest.ScheduleEndDate.length - 5));

                $('.ifbook_items[data-PlacerOrderNO="' + placerOrderNO + '"]').find('.observationlocation').text(page.scheduleExamRequest.ScheduleResourceName + "-" + (page.scheduleExamRequest.ResourceLocation || ""));
                page.schedule.printAfterAutoSave(page.scheduleExamRequest, page);//根据参数预约保存后打印预约成功的回执单。
                page.scheduleExamRequestOld = JSON.parse(JSON.stringify(page.scheduleExamRequest));
            });
        },

        //一键预约多个检查申请
        saveMultiExamSchedule: function () {
            var list = [];
            for (var i = 0; i < page.unFinishList.length; i++) {
                if (page.unFinishList[i].NeedScheduleFlag){
                    if(page.unFinishList[i].GroupID && page.unFinishList[i].orderList.length > 0){
                        for (var j = 0; j < page.unFinishList[i].orderList.length; j++) {
                            list.push(page.unFinishList[i].orderList[j]);
                        }
                    } else{
                        list.push(page.unFinishList[i]);
                    }
                }
            }

            if(list.length == 0){
                page.schedule.alert('目前您没有可以自助预约的检查申请!');
            }

            if(list.length > 0){
                imcis.ajax(page.relativeUrl + 'SaveExamScheduleAuto', list, true, function (data) {
                    if (data && data.success) {
                        for (var i = 0; i < data.resultList.length; i++) {
                            var exam = null, index = 0;
                            $.each(page.unFinishList, function (idx, n) {
                                if (n.PlacerOrderNO == data.resultList[i].PlacerOrderNO) {
                                    exam = n;
                                    index = idx;

                                    return false;
                                } else if (n.PlacerOrderNO.indexOf(data.resultList[i].PlacerOrderNO) > -1) {
                                    exam = n;
                                    index = idx;

                                    return false;
                                }
                            });

                            if (exam) {
                                exam.ScheduleID = data.resultList[i].ScheduleID;
                                exam.ScheduleResourceUID = data.resultList[i].ScheduleResourceUID;
                                exam.ScheduleResourceName = data.resultList[i].ScheduleResourceName;
                                exam.ScheduleStartDate = data.resultList[i].ScheduleStartDate;
                                exam.ScheduleEndDate = data.resultList[i].ScheduleEndDate;
                                exam.ScheduleNotice = data.resultList[i].ScheduleNotice;
                                exam.ResourceLocation = data.resultList[i].ResourceLocation;
                                exam.ScheduleFlag = true;
                                exam.printFlag = true;
                                exam.ScheduleStatus = 0;
                                exam.ResultStatus = "预约完成";
                                page.printTotal++;
                                
                                page.finishList.push(exam);
                                page.unFinishList.splice(index, 1);

                                try {
                                    var result = SelfClientBound.save(exam.PlacerOrderNO);

                                    if (result) {
                                        page.schedule.alert(result);
                                    }
                                } catch (ex) { }
                            }
                            page.schedule.printAfterAutoSave(exam, page);//根据参数预约保存后打印预约成功的回执单。
                            
                        }

                        pageEvent.bindAfterSave();
                        page.showMultiBtn();


                        if(page.unFinishList.length == 0){
                            try{
                                var result = SelfClientBound.finish();

                                if(result) {
                                    page.schedule.alert(result);
                                }
                            }catch(ex){}
                        }
                    } else if(data.errorMsg){
                        page.schedule.alert(data.errorMsg);
                    }
                });
            }
        },

        //获取单个申请的预约资源排班+1
        getScheduleInfoCallback: function (data) {
            var showRemainNumber = page.schedule.GetSysParameterValueByExamRequest(data, selfScheduleShowRemainNumber);
            page.scheduleExamRequest.ScheduleResourceUID = data.ResourceUID;
            page.scheduleExamRequest.ScheduleResourceName = data.ResourceName;
            page.scheduleExamRequest.ScheduleStartDate = data.ScheduleDate + " " + data.ScheduleTime.split('-')[0];
            page.scheduleExamRequest.ScheduleEndDate = data.ScheduleDate + " " + data.ScheduleTime.split('-')[1];
            page.scheduleExamRequest.Quantity = data.Quantity;
            page.scheduleExamRequest.OccupyNumber = data.OccupyNumber;

            page.scheduleExamRequest.ScheduleArrangeList = [];

            $.each(data.ScheduleArrangeResourceInfoList, function (i, n) {
                if (n.ResourceUID == data.ResourceUID) {
                    $('#time_container').attr('data-resourceuid', data.ResourceUID)
                                        .attr('data-resourcename', data.ResourceName)
                                        .attr('data-resourcelocation', n.ResourceLocation);
                    $('#time_container .day_items').removeClass('actived_item');
                    $('#time_container .day_0').addClass('actived_item');

                    if (n.ScheduleArrangeDateInfoList[0].PregnantWeek) {
                        $('#time_container .day_0').append('<span class="pregnantWeek" data-i="0"> ' + n.ScheduleArrangeDateInfoList[0].PregnantWeek + '</span>');
                    }
                    for (var j = 0; j < n.ScheduleArrangeDateInfoList.length; j++) {
                        var arrangeDay = imcis.convertDateFromJson(n.ScheduleArrangeDateInfoList[j].ArrangeDay, true);
                        $('#time_container .day_' + j + ' .myd').text(arrangeDay);
                        var scheduleArrange = { 
                            groupList: [],
                            '上午': { times: [], remainNumber: 0 },
                            '下午': { times: [], remainNumber: 0 },
                            pregnantWeek: n.ScheduleArrangeDateInfoList[0].PregnantWeek
                        };
                        var timeList = n.ScheduleArrangeDateInfoList[j].ScheduleArrangeTimeInfoList;
                        for (var i = 0; i < timeList.length; i++) {
                            if(timeList[i].AfternoonFlag) {
                                if(scheduleArrange['下午'].times.length == 0) {
                                    scheduleArrange.groupList.push('下午');
                                }
                                scheduleArrange['下午'].times.push(timeList[i]);
                                scheduleArrange['下午'].remainNumber += timeList[i].Quantity - timeList[i].AppointmentQuantity;
                            } else {
                                if(scheduleArrange['上午'].times.length == 0) {
                                    scheduleArrange.groupList.push('上午');
                                }
                                scheduleArrange['上午'].times.push(timeList[i]);
                                scheduleArrange['上午'].remainNumber += timeList[i].Quantity - timeList[i].AppointmentQuantity;
                            }

                            if (data.ScheduleDate == arrangeDay 
                                && data.ScheduleTime == timeList[i].StartTime + "-" + timeList[i].EndTime) {
                                scheduleArrange.scheduleGroupName = timeList[i].AfternoonFlag ? '下午' : '上午';
                            }
                        }
                        page.scheduleExamRequest.ScheduleArrangeList.push(scheduleArrange);

                        var arrangeWeek = '';
                        switch (n.ScheduleArrangeDateInfoList[j].ArrangeWeek) {
                            case 7:
                                arrangeWeek = "周日";
                                break;
                            case 1:
                                arrangeWeek = "周一";
                                break;
                            case 2:
                                arrangeWeek = "周二";
                                break;
                            case 3:
                                arrangeWeek = "周三";
                                break;
                            case 4:
                                arrangeWeek = "周四";
                                break;
                            case 5:
                                arrangeWeek = "周五";
                                break;
                            case 6:
                                arrangeWeek = "周六";
                                break;
                        }
                        $('#time_container .day_' + j + ' .week').text(arrangeWeek);
                        if ($('#time_container .day_' + j + ' .pregnantWeek').length == 0) {
                            var pollHtml = showRemainNumber == "1" ? '<span class="remainNumber">&nbsp;剩余' + (scheduleArrange["上午"].remainNumber + scheduleArrange['下午'].remainNumber) + '</span>' : "<span></span>";
                            $('#time_container .day_' + j).append(pollHtml);
                        }
                    }
                }
            });
            pageEvent.addDateGroup(showRemainNumber, page.scheduleExamRequest.ScheduleArrangeList[0]);
        },

        //添加日期下的时间组
        addDateGroup: function (showRemainNumber, scheduleArrange) {
            $('#time_container .ampm_title').html('');
            for (var i = 0; i < scheduleArrange.groupList.length; i++) {
                var pollHtml = showRemainNumber == "1" ? '<span style="font-size:20px;">&nbsp;剩余' + scheduleArrange[scheduleArrange.groupList[i]].remainNumber + '</span>' : "";
                var html = '';
                if (scheduleArrange.scheduleGroupName === scheduleArrange.groupList[i] || (!scheduleArrange.scheduleGroupName && i === 0)) {
                    html = '<div class="ampm pull-left actived_item" data-groupname="' + scheduleArrange.groupList[i] + '" >' +
                                    scheduleArrange.groupList[i] + pollHtml +
                            '</div>';
                } else {
                    html = '<div class="ampm pull-left" data-groupname="' + scheduleArrange.groupList[i] + '" >' +
                                    scheduleArrange.groupList[i] + pollHtml +
                            '</div>';
                }

                $('#time_container .ampm_title').append(html);
            }
               
            //时间段
            pageEvent.addGroupTime(showRemainNumber, scheduleArrange, (scheduleArrange.scheduleGroupName ||  scheduleArrange.groupList[0]), 0)
        },

        //时间组添加时间段+1
        addGroupTime: function (showRemainNumber, scheduleArrange, groupName, timesPageNum) {
            if (scheduleArrange[groupName]) {
                var times = scheduleArrange[groupName].times;
                var temp = '';
                var totalPage = Math.ceil(times.length * 1.0 / 16);
                var rowsNum = (timesPageNum + 1 == totalPage) ? times.length  - timesPageNum * 16 : 16;
                for (var i = timesPageNum * 16; i < timesPageNum * 16 + rowsNum; i++) {
                    var pollHtml = showRemainNumber == "1" ? '<span style="font-size:16px;display:block;width:100%;text-align:center;">剩余' + (times[i].Quantity - times[i].AppointmentQuantity) + '</span>' : "";
                    var pPadding = showRemainNumber == "1" ? "p-Padding" : "";
                    var time = times[i].StartTime + "-" + times[i].EndTime;
                    switch (times[i].ScheduleTimeStatus) {
                        case 3:
                        case 4:
                            //不可预约时间
                            temp += '<div class="pull-left schedule-time schedule-disable ' + pPadding + '" data-uid="' + times[i].TimeDetailUID + '" data-quantity="' + times[i].Quantity + '" data-resourceuid="' + ( times[i].ResourceUID || '') + '" data-resourcename="' + ( times[i].ResourceName || '') + '" ><span class="scheduleTime">' + time + '</span>' + pollHtml + '</div>';
                            break;
                        case 0://选中的时间
                            temp += '<div class="pull-left schedule-time schedule-current ' + pPadding + '" data-uid="' + times[i].TimeDetailUID + '" data-quantity="' + times[i].Quantity + '" data-resourceuid="' + ( times[i].ResourceUID || '') + '" data-resourcename="' + ( times[i].ResourceName || '') + '" ><span class="scheduleTime">' + time + '</span>' + pollHtml + '</div>';
                            break;
                        case 1:
                            //选中的时间
                            temp += '<div class="pull-left schedule-time schedule-finish ' + pPadding + '" data-uid="' + times[i].TimeDetailUID + '" data-quantity="' + times[i].Quantity + '" data-resourceuid="' + ( times[i].ResourceUID || '') + '" data-resourcename="' + ( times[i].ResourceName || '') + '" ><span class="scheduleTime">' + time + '</span>' + pollHtml + '</div>';
                            break;
                        default:
                            //可预约时间
                            temp += '<div class="pull-left schedule-time schedule-enable ' + pPadding + '" data-uid="' + times[i].TimeDetailUID + '" data-quantity="' + times[i].Quantity + '" data-resourceuid="' + ( times[i].ResourceUID || '') + '" data-resourcename="' + ( times[i].ResourceName || '') + '" ><span class="scheduleTime">' + time + '</span>' + pollHtml + '</div>';
                            break;
                    }
                }
                $('#time_detail_container').html(temp);

                if (totalPage == 1) {
                    $('#uppage').css({ 'background-color': '#DFDFDF' }).attr('disable', 'true');
                    $('#nextpage').css({ 'background-color': '#DFDFDF' }).attr('disable', 'true');
                } else if (timesPageNum == 0) {
                    $('#uppage').css({ 'background-color': '#DFDFDF' }).attr('disable', 'true');
                    $('#nextpage').css({ 'background-color': '#00a2ff' }).attr('disable', 'false');
                } else if (timesPageNum + 1 == totalPage) {
                    $('#uppage').css({ 'background-color': '#00a2ff' }).attr('disable', 'false');
                    $('#nextpage').css({ 'background-color': '#DFDFDF' }).attr('disable', 'true');
                } else {
                    $('#uppage').css({ 'background-color': '#00a2ff' }).attr('disable', 'false');
                    $('#nextpage').css({ 'background-color': '#00a2ff' }).attr('disable', 'false');
                }

                //预约时间段上一页
                $('#uppage').off();
                $('#uppage').on('click', function () {
                    if (timesPageNum == 0) { 
                        return false;
                    } else {
                        timesPageNum--;
                        pageEvent.addGroupTime(showRemainNumber, scheduleArrange, groupName, timesPageNum);
                    }
                });
                //预约时间段下一页
                $('#nextpage').off();
                $('#nextpage').on('click', function () {
                    if(timesPageNum == totalPage -1){
                        return false;
                    } else {
                        timesPageNum++;
                        pageEvent.addGroupTime(showRemainNumber, scheduleArrange, groupName, timesPageNum);
                    }
                });
            }
        },

        //切换时间组+1
        changeGroup: function () {
            $('.ampm').removeClass('actived_item');
            $(this).addClass('actived_item');
            var scheduleArrange = page.scheduleExamRequest.ScheduleArrangeList[page.dateIndex]; 
            var serviceSectID = $("#time_container>.bar>.ServiceSectID").text();
            var showRemainNumber = page.schedule.GetSysParameterValueByExamRequest({ ServiceSectID: serviceSectID}, selfScheduleShowRemainNumber);
            pageEvent.addGroupTime(showRemainNumber, scheduleArrange, $(this).data("groupname"), 0);
        },

        //选中时间+1
        selectTime: function () {
            if ($(this).hasClass('schedule-disable')) {
                return;
            } else if ($(this).hasClass('schedule-enable')) {
                $('#time_container .schedule-current').removeClass('schedule-current').addClass('schedule-enable');
                $(this).removeClass('schedule-enable').addClass('schedule-current');
            } else if ($(this).hasClass('schedule-finish')) {
                $('#time_container .schedule-current').removeClass('schedule-current').addClass('schedule-enable');
            }

           var $source = $('#time_container'); 

           page.scheduleExamRequest.ScheduleResourceUID = $(this).attr('data-resourceuid') || $source.attr('data-resourceuid');
           page.scheduleExamRequest.ScheduleResourceName =  $(this).attr('data-resourcename') || $source.attr('data-resourcename');

            //var scheduleTime = $(this).text();
            var scheduleTime = $(this).find(".scheduleTime").text();
            var scheduleDate = $('#time_container .day_items.actived_item .myd').text();

            page.scheduleExamRequest.ScheduleStartDate = scheduleDate + " " + scheduleTime.split('-')[0];
            page.scheduleExamRequest.ScheduleEndDate = scheduleDate + " " + scheduleTime.split('-')[1];
            page.scheduleExamRequest.Quantity = $(this).data('quantity');

            if (page.scheduleExamRequest.ScheduleFlag) {
                if (page.scheduleExamRequest.ScheduleResourceName == page.scheduleExamRequest.OriginalScheduleResourceName &&
                            page.scheduleExamRequest.ScheduleStartDate == page.scheduleExamRequest.OriginalScheduleStartDate &&
                            page.scheduleExamRequest.ScheduleEndDate == page.scheduleExamRequest.OriginalScheduleEndDate) {
                    page.scheduleExamRequest.ChangeFlag = false;
                } else {
                    page.scheduleExamRequest.ChangeFlag = true;
                }
            }
        },

        //切换日期
        changeDate: function (that) {
            var $that = $(that);
            var date = $that.find('.myd').text();

            if(!date){
                return;
            }

            $('.day_items.actived_item').removeClass('actived_item');
            $that.addClass('actived_item');
            page.dateIndex = $(that).data("i");
            
            var scheduleArrange = page.scheduleExamRequest.ScheduleArrangeList[page.dateIndex];
            var now = new Date();
            var isGroupName = false;
            if (date == now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate()) {
                now = new Date(date + " " + now.getHours() + ":" + now.getMinutes());

                for (var i = 0; i < scheduleArrange.groupList.length; i++) {
                    var times = scheduleArrange[scheduleArrange.groupList[i]].times;
                    
                    for (var j = 0; j < times.length; j++) {
                        var start = new Date(date + " " + times[j].StartTime);
                        var end = new Date(date + " " + times[j].EndTime);

                        if (now >= start && now <= end) {
                            scheduleArrange.scheduleGroupName = times[j].GroupName;
                            isGroupName = true;
                            break;
                        }
                    }

                    if (isGroupName) {
                        break;
                    }
                }
            }
            if (!isGroupName) {
                scheduleArrange.scheduleGroupName = scheduleArrange.groupList[0];
            }
            var serviceSectID = $("#time_container>.bar>.ServiceSectID").text();
            var showRemainNumber = page.schedule.GetSysParameterValueByExamRequest({ ServiceSectID: serviceSectID }, selfScheduleShowRemainNumber);
            var index = $("#time_container>.second_list .pregnantWeek").attr("data-i");
            if (typeof index != "undefined") {
                $('#time_container .day_' + index + ' .pregnantWeek').remove();
                if (showRemainNumber == "1") {
                    var scheduleArrange2 = page.scheduleExamRequest.ScheduleArrangeList[index];
                    var pollHtml = '<span class="remainNumber">&nbsp;剩余' + (scheduleArrange2["上午"].remainNumber + scheduleArrange2['下午'].remainNumber) + '</span>';
                    $('#time_container .day_' + index).append(pollHtml);
                    $('#time_container .day_' + page.dateIndex + ' .remainNumber').remove();
                }
            }
            if (scheduleArrange.pregnantWeek) {
                $('#time_container .day_' + page.dateIndex).append('<span class="pregnantWeek" data-i="' + page.dateIndex + '"> ' + scheduleArrange.pregnantWeek + '</span>');
            }
            pageEvent.addDateGroup(showRemainNumber, scheduleArrange);
        },

        //预约左右移动
        moveSchedule:function(){
            var $this = $(this);
            var type="";
            var list = [];

            switch($this.data('arrowposition')){
                case "unfinishleft":
                    if(page.unFinishList.current === 0){
                        $this.find('img').css('visibility', 'hidden');
                        return;
                    }

                    page.unFinishList.current--;
                    if(page.unFinishList.current === 0){
                        $this.find('img').css('visibility', 'hidden');
                    }
                    $('.unfinishright img').css('visibility', 'visible');
                    
                    type = "unfinish";
                    list.push(page.unFinishList[page.unFinishList.current * 2]);
                    list.push(page.unFinishList[page.unFinishList.current * 2 + 1]);
                    break;
                case "unfinishright":
                    if((page.unFinishList.current+ 1) * 2 >= page.unFinishList.length){
                        $this.find('img').css('visibility', 'hidden');
                        return;
                    }

                    page.unFinishList.current++;
                    if((page.unFinishList.current+ 1) * 2 >= page.unFinishList.length){
                        $this.find('img').css('visibility', 'hidden');
                    }
                    $('.unfinishleft img').css('visibility', 'visible');

                    type = "unfinish";
                    if(page.unFinishList.length >= (page.unFinishList.current + 1) * 2){
                        list.push(page.unFinishList[page.unFinishList.current * 2]);
                        list.push(page.unFinishList[page.unFinishList.current * 2 + 1]);
                    } else {
                        list.push(page.unFinishList[page.unFinishList.current * 2]);
                    }
                    break;
                case "finishleft":
                    if (scheduleSelfShowUnScheduleList) {
                        if (page.finishList.current === 0) {
                            $this.find('img').css('visibility', 'hidden');
                            return;
                        }

                        page.finishList.current--;
                        if (page.finishList.current === 0) {
                            $this.find('img').css('visibility', 'hidden');
                        }
                        $('.finishright img').css('visibility', 'visible');

                        type = "finish";
                        list.push(page.finishList[page.finishList.current * 2]);
                        list.push(page.finishList[page.finishList.current * 2 + 1]);
                    } else {
                        if (page.finishList.current === 0) {
                            $this.find('img').css('visibility', 'hidden');
                            return;
                        }

                        page.finishList.current--;
                        if (page.finishList.current === 0) {
                            $this.find('img').css('visibility', 'hidden');
                        }
                        $('.finishright img').css('visibility', 'visible');

                        type = "finish";
                        list.push(page.finishList[page.finishList.current * 4]);
                        list.push(page.finishList[page.finishList.current * 4 + 1]);
                        list.push(page.finishList[page.finishList.current * 4 + 2]);
                        list.push(page.finishList[page.finishList.current * 4 + 3]);
                    }
                    
                    break;
                case "finishright":
                    if (scheduleSelfShowUnScheduleList) {
                        if ((page.finishList.current + 1) * 2 >= page.finishList.length) {
                            $this.find('img').css('visibility', 'hidden');
                            return;
                        }

                        page.finishList.current++;
                        if ((page.finishList.current + 1) * 2 >= page.finishList.length) {
                            $this.find('img').css('visibility', 'hidden');
                        }
                        $('.finishleft img').css('visibility', 'visible');

                        type = "finish";
                        if (page.finishList.length >= (page.finishList.current + 1) * 2) {
                            list.push(page.finishList[page.finishList.current * 2]);
                            list.push(page.finishList[page.finishList.current * 2 + 1]);
                        } else {
                            list.push(page.finishList[page.finishList.current * 2]);
                        }
                       
                    } else {
                        if ((page.finishList.current + 1) * 4 >= page.finishList.length) {
                            $this.find('img').css('visibility', 'hidden');
                            return;
                        }

                        page.finishList.current++;
                        if ((page.finishList.current + 1) * 4 >= page.finishList.length) {
                            $this.find('img').css('visibility', 'hidden');
                        }
                        $('.finishleft img').css('visibility', 'visible');

                        type = "finish";
                        if (page.finishList.length >= (page.finishList.current + 1) * 4) {
                            list.push(page.finishList[page.finishList.current * 4]);
                            list.push(page.finishList[page.finishList.current * 4 + 1]);
                            list.push(page.finishList[page.finishList.current * 4 + 2]);
                            list.push(page.finishList[page.finishList.current * 4 + 3]);
                        } else if (page.finishList.length >= (page.finishList.current + 1) * 4 - 1) {
                            list.push(page.finishList[page.finishList.current * 4]);
                            list.push(page.finishList[page.finishList.current * 4 + 1]);
                            list.push(page.finishList[page.finishList.current * 4 + 2]);
                        } else if (page.finishList.length >= (page.finishList.current + 1) * -2) {
                            list.push(page.finishList[page.finishList.current * 4]);
                            list.push(page.finishList[page.finishList.current * 4 + 1]);
                        } else {
                            list.push(page.finishList[page.finishList.current * 4]);
                        }
                    }
                    
                    
                    break;
                default:
                    break;
            }

            if (scheduleSelfShowUnScheduleList) {
                if (type == "finish") {
                    $('#main_container .finish-container').html('');
                    for (var i = 0; i < list.length; i++) {
                        page.bindFinish(list[i], page.finishList.current * 2 + i + 1);
                    }
                } else {
                    $('#main_container .un-finish-container').html('');
                    for (var i = 0; i < list.length; i++) {
                        page.bindUnFinish(list[i], page.unFinishList.current * 2 + i + 1);
                    }
                }
            } else {
                if (type == "finish") {
                    $('#main_container .finish-container').html('');
                    for (var i = 0; i < list.length; i++) {
                        page.bindFinish(list[i], page.finishList.current * 4 + i + 1);
                    }
                }
            }

            $('.un-finish-container .not_schedule').on('click', function (e) {
                pageEvent.showNotScheduleMemo($(this), page.unFinishList);
                if (e && e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    window.event.cancelBubble = true;
                }

            });
            $('.finish-container .not_schedule').on('click', function (e) {
                pageEvent.showNotScheduleMemo($(this), page.finishList);
            });
            
        },

        //黑名单限制及提示
        scheduleLimit: function () {
            var $this = this;
            var notEditType = $($this).attr("data-notEditType");
            var notCancelType = $($this).attr("data-notCancelType");
            switch (notEditType) {
                case "allowSelfEditTimes":
                    var times = $($this).attr("data-editTimes");
                    page.schedule.alert("自助预约已超过" + times + "次，如有需要请联系相关科室。");
                    break;
                case "allowUpdateSchedule":
                    var times = $($this).attr("data-allowUpdateTimes");
                    var scheduleStartDate = $($this).attr("data-ScheduleStartDate");
                    var resultStatus = $($this).attr("data-resultStatus");
                    var patientClass = $($this).attr("data-patientClass");
                    var serviceSectID = $($this).attr("data-serviceSectID");
                    var scheduleRoute = $($this).attr("data-scheduleRoute");
                    var tip = $.trim(resultStatus) == "" ?
                        "预约开始时间" + scheduleStartDate + "前" + (times != null ? times : "") + "分钟不允许自助修改，如有需要请联系相关科室。" :
                        "检查状态=" + resultStatus + "的" + serviceSectID + "、" + patientClass + "、" + scheduleRoute + "不允许自助修改，如有需要请联系相关科室。";
                    page.schedule.alert(tip);
                    break;
                case "scheduleLimit":
                    break;
            }

            switch (notCancelType) {
                case "allowSelfCancelTimes":
                    var times = $($this).attr("data-cancelTimes");
                    page.schedule.alert("自助取消预约已超过" + times + "次，如有需要请联系相关科室。");
                    break;
                case "allowCancelSchedule":
                    var times = $($this).attr("data-allowCancelTimes");
                    var scheduleStartDate = $($this).attr("data-ScheduleStartDate");
                    page.schedule.alert("预约开始时间" + scheduleStartDate + "前" + (times != null ? times : "") + "分钟不允许自助取消，如有需要请联系相关科室。");
                    break;
                case "cancelResultStatus":
                    var resultStatus = $($this).attr("data-resultStatus");
                    var patientClass = $($this).attr("data-patientClass");
                    var serviceSectID = $($this).attr("data-serviceSectID");
                    var scheduleRoute = $($this).attr("data-scheduleRoute");
                    page.schedule.alert("检查状态=" + resultStatus + "的" + serviceSectID + "、" + patientClass + "、" + scheduleRoute + "不允许自助取消，如有需要请联系相关科室。");
                    break;
                case "scheduleLimit":
                    break;
            }

            if (scheduleLimit != "" && scheduleLimit != "0") {
                if (limitMsg != "")
                    page.schedule.alert(limitMsg.replace(/\\n/g, '<br/>'));
                if (scheduleLimit != "1")
                    return true;
            }
            return false;
        },

        //选择要打印的项
        selectPrint: function () {
            var placerOrderNO = $(this).closest('.ifbook_items').data('placerorderno');
            var printExam = null;
            $.each(page.finishList, function (i, n) {
                if (n.PlacerOrderNO == placerOrderNO) {      
                    printExam = n;
                    return false;
                }
            });
            if ($(this).parent().find('.print_img').attr('class').indexOf('print_img_cancel') > -1) {
                if (scheduleSelfPrintExamScheduleReceiptPayment && !printExam.PaymentsFlag) {
                    var allowNotPaymentPrint = page.schedule.GetSysParameterValueByExamRequest(printExam, scheduleSelfPrintExamScheduleReceiptPayment);
                    if (allowNotPaymentPrint === "0") {
                        page.schedule.alert('此申请单未交费，不允许打印！');
                        return;
                    }
                }

                var allowPrintCount = page.schedule.GetSysParameterValueByExamRequest(printExam, scheduleSelfPrintExamScheduleReceiptTimes);
                if (!allowPrintCount && printExam.ReceiptPrintCount != null && printExam.ReceiptPrintCount >= 1) {
                    page.schedule.alert('此申请单的打印次数已超，不允许打印，请到人工窗口处理！');
                    return;
                } else if (printExam.ReceiptPrintCount != null && allowPrintCount !== '' && printExam.ReceiptPrintCount >= allowPrintCount) {
                    page.schedule.alert('此申请单的打印次数已超，不允许打印，请到人工窗口处理！');
                    return;
                }
                page.printTotal++;
                $(this).parent().find('.print_img').removeClass('print_img_cancel').addClass('print_img_check');
            } else {
                if(page.printTotal > 0)
                    page.printTotal--;
                $(this).parent().find('.print_img').removeClass('print_img_check').addClass('print_img_cancel');
            }

            printExam.printFlag = !printExam.printFlag;
            $('#print').text('打印预约单' + (page.printTotal === 0 ? "" : "（" + page.printTotal + "）"));
        },

        //打印
        print: function () {
            var printNum = 0;
            $.each(page.finishList, function(i, n){
                if(n.printFlag) {
                    printNum++;
                    try {
                        if ($('#hdnSelfLocalPrintReceipt').val() == '1') {//调用自助机自身的打印 
                            var result = SelfClientBound.print(n.PlacerOrderNO);
                            if (result) {
                                alert(result);
                            } 
                        } else {
                            var defaultPrint = '',
                                defaultCustomSize = '';
                            var resourcePrint = '',
                                resourceCustomSize = '';
                            if (printSet && printSet.length > 0) {
                                for (var i = 0; i < printSet.length; i++) {
                                    var set = printSet[i];
                                    if (n.ScheduleResourceName && set[n.ScheduleResourceName] !== undefined) {
                                        resourcePrint = set[n.ScheduleResourceName];
                                        resourceCustomSize = set.scheduleReceiptPrintCustomSize;
                                    } else if (set['defaultPrint'] !== undefined) {
                                        defaultPrint = set['defaultPrint'];
                                        defaultCustomSize = set.scheduleReceiptPrintCustomSize;
                                    }
                                }
                            } else if (printExamSchedulePage != "") {
                                var pageSize = "";
                                var pageArrs = printExamSchedulePage.split("|");
                                for (var index in pageArrs) {
                                    if (pageArrs[index].indexOf("=") == -1) {
                                        pageSize = pageArrs[index];
                                    } else {
                                        var pageArr = pageArrs[index].split("=");
                                        if (pageArr[0] == n.ServiceSectID)
                                            pageSize = pageArr[1];
                                    }
                                }
                                imcis.cookie.setConfig('defaultPrint', "默认打印机|" + pageSize + "|0");
                                imcis.cookie.setConfig('scheduleReceiptPrintCustomSize', "0");
                            } else {
                                defaultPrint = "默认打印机|A4|0";
                                defaultCustomSize = "1";
                            }
                            if (resourcePrint) {
                                imcis.cookie.setConfig('defaultPrint', resourcePrint);
                                imcis.cookie.setConfig('scheduleReceiptPrintCustomSize', resourceCustomSize);
                            } else if (defaultPrint) {
                                imcis.cookie.setConfig('defaultPrint', defaultPrint);
                                imcis.cookie.setConfig('scheduleReceiptPrintCustomSize', defaultCustomSize);
                            }
                            page.schedule.print(n, page);
                        } 

                        
                    }  catch (e) {}
                }
            });
            if (printNum>0&&$('#hdnSelfLocalPrintReceipt').val() == '1') {
                page.schedule.alert('打印成功，请取走回执单!(<span id="layui-layer-content-time-local">3</span>秒后自动关闭)');
                var timer = setInterval(function () {
                    var time = parseInt($("#layui-layer-content-time-local").text());
                    time--;
                    $("#layui-layer-content-time-local").text(time);
                    if (time <= 0) {
                        layer.closeAll('dialog');
                        clearInterval(timer);
                    }
                }, 1000);
            }
            if (printNum == 0) {
                page.schedule.alert('请勾选需要打印的预约单!');
            } 
        },

        //未预约的保存后重新绑定
        bindAfterSave: function () {
            $('.unbooknum').text('（' + page.unFinishList.length + '）');
            $('.booknum').text('（' + page.finishList.length + '）');

            $('#main_container .finish-container').html('');
            if (page.finishList.length <= 2) {
                for (var i = 0 ; i < page.finishList.length; i++) {
                    page.bindFinish(page.finishList[i], i + 1);
                }

                $('.finishright').find('img').css('visibility', 'hidden');
                $('.finishleft').find('img').css('visibility', 'hidden');
            } else {
                page.finishList.current = Math.ceil(page.finishList.length * 1.0 / 2);
                for (var i = ((page.finishList.current - 1) * 2) ; i < page.finishList.length; i++) {
                    page.bindFinish(page.finishList[i], i + 1);
                }

                $('.finishright').find('img').css('visibility', 'hidden');
                $('.finishleft').find('img').css('visibility', 'visible');
            }

            $('#main_container .un-finish-container').html('');
            if (page.unFinishList.length <= 2) {
                for (var i = 0 ; i < page.unFinishList.length; i++) {
                    page.bindUnFinish(page.unFinishList[i], i + 1);
                }
                $('.unfinishright').find('img').css('visibility', 'hidden');
                $('.unfinishleft').find('img').css('visibility', 'hidden');
            } else {
                if (page.unFinishList.length > (page.unFinishList.current + 1) * 2) {
                    page.bindUnFinish(page.unFinishList[page.unFinishList.current * 2], page.unFinishList.current * 2 + 1);
                    page.bindUnFinish(page.unFinishList[page.unFinishList.current * 2 + 1], page.unFinishList.current * 2 + 2);

                    $('.unfinishright').find('img').css('visibility', 'visible');
                    $('.unfinishleft').find('img').css('visibility', 'visible');
                } else if (page.unFinishList.length > page.unFinishList.current * 2 && page.unFinishList.length < (page.unFinishList.current + 1) * 2) {
                    page.bindUnFinish(page.unFinishList[page.unFinishList.current * 2], page.unFinishList.current * 2 + 1);

                    $('.unfinishright').find('img').css('visibility', 'hidden');
                    $('.unfinishleft').find('img').css('visibility', 'visible');
                } else {
                    if (page.unFinishList.current > 0) {
                        page.unFinishList.current--;
                        page.bindUnFinish(page.unFinishList[page.unFinishList.current * 2], page.unFinishList.current * 2 + 1);
                        page.bindUnFinish(page.unFinishList[page.unFinishList.current * 2 + 1], page.unFinishList.current * 2 + 2);

                        $('.unfinishright').find('img').css('visibility', 'hidden');
                        $('.unfinishleft').find('img').css('visibility', 'visible');
                    }
                }
            }

            $('#print').text('打印预约单' + (page.printTotal === 0 ? "" : "（" + page.printTotal + "）"));
        },

        showScheduleNotice: function(){
            var  $this = $(this);
            var placerOrderNO = $this.closest('.ifbook_items').data("placerorderno");
            $.each(page.finishList, function(i, n){
                if (placerOrderNO == n.PlacerOrderNO) {
                    layer.confirm(n.ScheduleNotice, {
                        btn: ['关闭'], //按钮
                        area: ['600px', '500px']
                    }, function () {
                        layer.closeAll('dialog');
                        return false;
                    })

                    return false;
                }
            });
        },

        back: function(ev){
            ev = ev || event;
            try {
                var result = SelfClientBound.back();

                if(result) {
                    page.schedule.alert(result);
                }
            } catch(ex){}

            ev.stopPropagation();    
        },

        //显示不提供自助预约原因
        showNotScheduleMemo: function ($this, list) {
            var placerOrderNO = $this.closest('.ifbook_items').data("placerorderno");
            $.each(list, function (i, n) {
                if (placerOrderNO == n.PlacerOrderNO) {
                    if (n.ScheduleStatus + '' === '0' && n.OperationMemo && n.OperationMemo.length > 10) {
                        page.schedule.alert(n.OperationMemo);
                        return false;
                    } else if (n.OperationMemo && n.OperationMemo.length > 10) {
                        page.schedule.alert(n.OperationMemo);
                        return false;
                    }
                }
            });
        }

    };

    page.init();
})();

Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}
